package com.lwm.string;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author liweimin
 * @date 2020/10/15 10:16
 * @description
 */
public class StringMethod {
    @Test
    public void test01() {
        String s1 = "helloworld";
        System.out.println(s1.length());
        System.out.println(s1.charAt(0));
        System.out.println(s1.isEmpty());
        System.out.println(s1.toUpperCase());
        String s = " s ohkl ohi rowe rweoiur ouwe ";
        //去掉两边的空格
        System.out.println(s.trim());
    }

    @Test
    public void test03() {
        String s1 = "WWW";
        String s2 = "WWw";
        System.out.println(s1.equalsIgnoreCase(s2));
    }

    @Test
    public void test04() {
        String s = "dasda";
        String s1 = "sdadasda";
        System.out.println(s.concat(s1));
    }

    @Test
    public void test05() {
        String s = "aq";
        String s1 = "wq";
        System.out.println(s.compareTo(s1));
    }

    @Test
    public void test06() {
        String s = "fflkadfhafjajajajajajajajajajajajajafhffadas";
        //左闭右开
        System.out.println(s.substring(1, 5));
        CharSequence charSequence = s.subSequence(1, 5);
        System.out.println(charSequence);
    }

    @Test
    public void test07() {
        String s = "dsadasd";
        System.out.println(s.startsWith("d"));
        System.out.println(s.endsWith("asd"));
    }

    @Test
    public void test08() {
        String s = "fhsldf";
        System.out.println(s.contains("ldf"));
    }

    @Test
    public void test09() {
        String s = "dasdadsad";
        System.out.println(s.indexOf("a"));
        System.out.println(s.indexOf("a", 3));
        System.out.println(s.lastIndexOf("a"));
    }

    @Test
    public void test10() {
        String s = "ddadasdsadsa";
        System.out.println(s.replace("d", "WWW"));
        String d = "12ff234fsdf543gdfg43gergt545";
        System.out.println(d.replaceAll("\\d+", ",").replaceAll("^,|,$", ""));
        System.out.println(d.matches("||"));
        String a = "dsadasdrf-fsdsdf-fsdf-fsdf-34-54534";
        Arrays.stream(a.split("-")).forEach(System.out::println);
    }

    @Test
    /**
     * String 与char数组
     */
    public void test11() {
        String s = "123";
        System.out.println(Integer.parseInt(s));
        int a = 4658;
        System.out.println(String.valueOf(a));
    }

    @Test
    public void test12() {
        String s = "fbsdfdmnbasbfjwefjfabdsfasndf";
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            System.out.println(chars[i]);
        }
        char[] ch = {'q', 'w', 'w', 'r', 'e'};
        String s1 = new String(ch);
        System.out.println(s1);
    }

    @Test
    /**
     * String与byte数组
     */
    public void test13() {
        String s = "fsjfsdfsdfsdfs";
        byte[] bytes = s.getBytes();
        System.out.println(Arrays.toString(bytes));
        for (byte b : s.getBytes()) {
            System.out.println(b);
        }
        if (s == "")
            System.out.println("s");
    }

    @Test
    public void test14() {
        /**
         * 常量与常量拼接---》常量
         * 变量+遍量----》变量
         */

    }
}
